import 'package:dear_lottery/Results/views/DL_resultDetailListItem.dart';
import 'package:dear_lottery/tools/DL_Config.dart';
import 'package:flutter/material.dart';

import '../tools/DL_drawNumbersView.dart';
import '../tools/models/DL_LottoModel.dart';

class DL_ResultDetailPageVC extends StatefulWidget {
  DL_ResultDetailPageVC({
    super.key,
    required this.lottoModel,
  });
  DL_LottoModel lottoModel;
  @override
  State<DL_ResultDetailPageVC> createState() => _DL_ResultDetailPageVCState();
}

class _DL_ResultDetailPageVCState extends State<DL_ResultDetailPageVC> {
  var _datas = [];
  var _firstPrizeMap = {};
  var _lottoModel = DL_LottoModel();

  @override
  void initState() {
    super.initState();

    _lottoModel = widget.lottoModel;
    _datas = _lottoModel.all_prize_num!;

    var firstPrizeNum = _lottoModel.first_prize_num![0];
    List<String> charArray = firstPrizeNum.split('');
    var balls = [];
    for (var i = 0; i < charArray.length; i++) {
      var ball = {
        'number': charArray[i],
        'isRight': false,
        'isNormal': true
      }; //isNormal代表是否对比中奖号码，true不用对比，false需要对比。isRight代表是否中奖号码
      balls.add(ball);
    }
    var title = '1st Prize';
    _firstPrizeMap = {
      'title': title,
      'prizeAmount': _lottoModel.first_prize.toString(),
      'balls': balls
    };

    ///模拟数据
    // var tempData = [
    //   [
    //     '649722',
    //   ],
    //   [
    //     '649722',
    //     '649723',
    //     '649723',
    //   ],
    //   [
    //     '649722',
    //     '649723',
    //     '649724',
    //     '649722',
    //     '649723',
    //   ],
    //   [
    //     '649722',
    //     '649723',
    //     '649724',
    //     '649722',
    //     '649723',
    //     '649724',
    //     '649722',
    //     '649723',
    //     '649724',
    //     '649722',
    //     '649723',
    //     '649722',
    //     '649723',
    //     '649724',
    //     '649722',
    //     '649723',
    //     '649724',
    //     '649722',
    //     '649723',
    //     '649724'
    //   ]
    // ];
    // for (int i = 0; i < tempData.length; i++) {
    //   Map ball = {
    //     'prizeAmount': '1000',
    //     'title': 'title',
    //     'number': [],
    //   };
    //   ball['number'] = tempData[i];
    //   _datas.add(ball);
    // }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          'Result Details',
          style: TextStyle(
            fontWeight: FontWeight.w600,
            fontSize: 18,
          ),
        ),
        backgroundColor: DL_Config.DL_MainColor,
        foregroundColor: Colors.white,
        centerTitle: true,
      ),
      body: Container(
        width: double.infinity,
        color: Colors.white,
        child: ListView.builder(
            itemCount: _datas.length,
            itemBuilder: (context, index) {
              if (index == 0) {
                // return DL_drawNumbersView(data: _firstPrizeMap);
                return drawingNumbersView();
              }

              var numberMap = _datas[index];
              return DL_ResultDetailListItem(numberMap: numberMap);
            }),
      ),
    );
  }

  Widget drawingNumbersView() {
    return Container(
      margin: const EdgeInsets.all(10),
      child: DL_drawNumbersView(data: _firstPrizeMap),
    );
  }
}
